package com.seu.algorithms.utils;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * Emoji 表情过滤
 *
 * @author liangfeihu
 * @since 2018/12/19 10:13
 */
public class EmojiUtils {
    private final static Pattern emoji = Pattern.compile("[\ud83c\udc00-\ud83c\udfff]|[\ud83d\udc00-\ud83d\udfff]|[\u2600-\u27ff]",
            Pattern.UNICODE_CASE | Pattern.CASE_INSENSITIVE);

    public static String filterEmoji(String source) {
        if (source != null) {
            Matcher emojiMatcher = emoji.matcher(source);
            if (emojiMatcher.find()) {
                source = emojiMatcher.replaceAll("*");
                return source;
            }
            return source;
        }
        return source;
    }

    public static void main(String[] args) {
        String test = "测试\uD83D\uDE06哈哈哈\uD83D\uDE02";
        System.out.println(filterEmoji(test));
    }

}
